﻿#include <Application.h>
#include <qfile.h>
#include <ui/Note.h>
#include <ui/PrimaryEditor.h>
#include <qmenu.h>
#include <qqmlapplicationengine.h>
#include <qabstractitemmodel.h>

primal::Application::Application()
	:
	argc{},
	argv{},
	mQApplication{ argc,argv },
	mTrayIcon{ QIcon{ ":/app_icon" } }
{
	QFile f_style{ ":/style/default/default_style" };
	if (!f_style.open(QIODevice::OpenModeFlag::ReadOnly))
	{
		Note::Error("没有打开样式资源！");
	}
	mQApplication.setStyleSheet(f_style.readAll());

	mQApplication.setWindowIcon(QIcon{ ":/app_icon" });
}

int primal::Application::run()
{
	mTrayIcon.show();

	QQmlApplicationEngine qml_engine{};
	auto ctx = qml_engine.rootContext();
	
	qml_engine.load(":/view/main_view");

	return mQApplication.exec();
}

primal::Application& primal::Application::Instance()
{
	static Application app{};
	return app;
}

int main()
{
	return primal::Application::Instance().run();
}